<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg">
  <head>
    <title>Working with XML and HTML</title>
    <link rel="stylesheet" type="text/css" href="docbook-epub.css"/>
    <link rel="stylesheet" type="text/css" href="kawa.css"/>
    <script src="kawa-ebook.js" type="text/javascript"/>
    <meta name="generator" content="DocBook XSL-NS Stylesheets V1.79.1"/>
    <link rel="prev" href="Evaluating-Scheme-expressions-from-Java.xhtml" title="Evaluating Scheme expressions from Java"/>
    <link rel="next" href="Formatting-XML.xhtml" title="Formatting XML"/>
  </head>
  <body>
    <header/>
    <section class="chapter" title="Working with XML and HTML" epub:type="chapter" id="XML-tools">
      <div class="titlepage">
        <div>
          <div>
            <h2 class="title">Working with XML and HTML</h2>
          </div>
        </div>
      </div>
      <p>Kawa has a number of features for working with XML, HTML,
and generated web pages.
</p>
      <p>In Kawa you don’t write XML or HTML directly.
Instead you write expressions that evaluate to “node objects”
corresponding to elements, attributes, and text.
You then write these node objects using either an XML or HTML format.
</p>
      <p>Many web-page-generating tools require you to work directly
with raw HTML, as for example:
</p>
      <pre class="screen">(display "&lt;p&gt;Don't use the &lt;code&gt;&amp;lt;blink&amp;gt;&lt;/code&gt; tag.&lt;/p&gt;")
</pre>
      <p>In Kawa you would instead do:
</p>
      <pre class="screen">(display (html:p "Don't use the " (html:code "&lt;blink&gt;") " tag."))
</pre>
      <p>The conversion from node objects to XML or HTML is handled by
the formatter (or serializer).
Some advantages of doing it this way are:
</p>
      <div class="itemizedlist" epub:type="list">
        <ul class="itemizedlist" style="list-style-type: disc; ">
          <li class="listitem" epub:type="list-item">
            <p>You don’t have to worry about quoting special characters.
Missing or incorrect quoting is a common source of bugs
and security problems on systems that work directly with text, such as PHP.
</p>
          </li>
          <li class="listitem" epub:type="list-item">
            <p>Some errors, such as mismatched element tags, are automatically avoided.
</p>
          </li>
          <li class="listitem" epub:type="list-item">
            <p>The generated XML can be validated as it is generated,
or even using compile-time type-checking.  (Kawa doesn’t yet do either.)
</p>
          </li>
          <li class="listitem" epub:type="list-item">
            <p>In an application that also reads XML,
you can treat XML that is read in and XML that is generated using
the same functions.
</p>
          </li>
        </ul>
      </div>
    </section>
    <footer>
      <div class="navfooter">
        <ul>
          <li>
            <b class="toc">
              <a href="Formatting-XML.xhtml">Formatting XML</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Creating-HTML-nodes.xhtml">Creating HTML nodes</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Creating-XML-nodes.xhtml">Creating XML nodes</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="XML-literals.xhtml">XML literals</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Server-side-scripts.xhtml">Web page scripts</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Self-configuring-page-scripts.xhtml">Self-configuring web page scripts</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="Servlets.xhtml">Installing web page scripts as Servlets</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="CGI-scripts.xhtml">Installing Kawa programs as CGI scripts</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="HTTP-requests.xhtml">Functions for accessing HTTP requests</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="HTTP-response.xhtml">Generating HTTP responses</a>
            </b>
          </li>
          <li>
            <b class="toc">
              <a href="XML-beyond-Scheme.xhtml">Using non-Scheme languages for XML/HTML</a>
            </b>
          </li>
        </ul>
        <p>
          Up: <a accesskey="u" href="pt01.xhtml">Part . Reference Documentation</a></p>
        <p>
        Previous: <a accesskey="p" href="Objects-Classes-and-Modules.xhtml">Object, Classes and Modules</a></p>
        <p>
        Next: <a accesskey="n" href="Miscellaneous.xhtml">Miscellaneous topics</a></p>
      </div>
    </footer>
  </body>
</html>
